<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>卡列表</title>

    <link href="../../resource/css/bootstrap.min.css?v=3.3.5" rel="stylesheet"
          th:href="@{/resource/css/bootstrap.min.css?v=3.3.5}"/>

    <link href="../../resource/hotui/css/font-awesome.min.css" th:href="@{/resource/hotui/css/font-awesome.min.css}"
          rel="stylesheet">
    <!-- Morris -->
    <link href="../../resource/css/plugins/morris/morris-0.4.3.min.css"
          th:href="@{/resource/css/plugins/morris/morris-0.4.3.min.css}" rel="stylesheet">

    <link href="../../resource/css/animate.min.css" rel="stylesheet" th:href="@{/resource/css/animate.min.css}"/>

    <link href="../../resource/hotui/css/style.min-1.0.8.css" th:href="@{/resource/hotui/css/style.min-1.0.8.css}"
          rel="stylesheet">
    <link href="../../resource/hotui/css/hotui.style.override.css"
          th:href="@{/resource/hotui/css/hotui.style.override.css}" rel="stylesheet"/>

    <link href="../../resource/hotui/css/switchery.min.css"
          th:href="@{/resource/hotui/css/switchery.min.css}" rel="stylesheet"/>

    <link href="../../resource/lib/bootstrap-daterangepicker/daterangepicker.min.css"
          th:href="@{/resource/lib/bootstrap-daterangepicker/daterangepicker.min.css}" rel="stylesheet">

    <link href="../../resource/lib/bootstrap-datepicker/css/bootstrap-datepicker.min.css"
          th:href="@{/resource/lib/bootstrap-datepicker/css/bootstrap-datepicker.min.css}" rel="stylesheet"/>
    <link href="../../resource/hotui/css/awesome-bootstrap-checkbox.min.css"
          th:href="@{/resource/hotui/css/awesome-bootstrap-checkbox.min.css}"
          rel="stylesheet">

    <style type="text/css">
        .hr-line-dashed {
            margin: 10px 0;
            height: 1px;
            border-top: 1px dashed #e7eaec;
            background-color: #fff;
            color: #fff;
        }

        .city-picker-selector select {

        }

        .nav-tabs input {
            width: 20px;
            height: 23px;
        }
    </style>
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight tooltip-demo">
    <!--search-->
    <form role="form" id="searchForm" class="search-panel" method="get" th:object="${condition}">
        <div class="row">
            <div class="col-lg-12">
                <div class="ibox">
                    <div class="ibox-content">
                        <div class="form-inline">
                            <input type="hidden" th:value="${status}" name="status"/>
                            <input type="hidden" th:value="${voltageStatus}" name="voltageStatus"/>
                            <input type="hidden" th:value="${dismantleStatus}" name="dismantleStatus"/>
                            <input type="hidden" th:value="${onlineStatus}" name="onlineStatus"/>
                            <input type="hidden" th:value="${pageIndex}" name="pageIndex"/>
                            <div class="form-group m-r-sm">
                                <label class="control-label">基站编号：</label>
                                <input type="text" class="form-control input-sm mb10" id="no" name="no"
                                       th:value="*{no}"
                                       placeholder="请输入完整编号"/>
                                <label class="control-label">基站类型：</label>
                                <select class="form-control" name="type" id="type">
                                    <option value="-1">全部</option>
                                    <option th:selected="*{type==0}" value="0">室外定位基站</option>
                                    <option th:selected="*{type==1}" value="1">室内融通基站</option>
                                </select>

                            </div>
                            <div style="float: right;">
                                <button type="button" class="btn btn-success" onclick="jsHelper.search()">筛选</button>
                                <button type="button" class="btn btn-success" onclick="jsHelper.searchAll()">显示全部
                                </button>
                                <button type="button" class="btn btn-success" onclick="jsHelper.setCard()">添加</button>
                                <button type="button" onclick="jsHelper.uploadUpdateExcelModal()"
                                        class="btn btn-success">导入
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <!--search-->

    <!--list-->
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins m-b-none">
                <div class="tabs-container">
                    <ul class="nav nav-tabs">
                        <li class="active"
                            th:class="${(condition.status==null&&condition.voltageStatus==null
                            &&condition.dismantleStatus==null&&condition.onlineStatus==null)?'active':''}">
                            <a th:href="@{/equipment/base/station/list}" href="#tab-2">全部</a>
                        </li>
                        <li th:class="${condition.status==true?'active':''}">
                            <a th:href="@{/equipment/base/station/list(status=true)}">
                                报警</a>
                        </li>
                        <li th:class="${condition.voltageStatus==1?'active':''}">
                            <a th:href="@{/equipment/base/station/list(voltageStatus=1)}">
                                低电压</a>
                        </li>
                        <li th:class="${condition.onlineStatus==false?'active':''}">
                            <a th:href="@{/equipment/base/station/list(onlineStatus=0)}">
                                离线</a>
                        </li>
                        <li th:class="${condition.dismantleStatus==false?'active':''}">
                            <a th:href="@{/equipment/base/station/list(dismantleStatus=0)}">
                                拆卸异常</a>
                        </li>
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active">
                            <div class="panel-body">
                                <table class="table table-bordered table-hover table-center">
                                    <tr>
                                        <th>序号</th>
                                        <th>基站编号</th>
                                        <th>设备类型</th>
                                        <th>基站类型</th>
                                        <th>设备版本</th>
                                        <th>阅读器地址</th>
                                        <th>描述</th>
                                        <th>是否节点</th>
                                        <th>在线状态</th>
                                        <th>报警状态</th>
                                        <th>电压状态</th>
                                        <th>防拆卸状态</th>
                                        <th>启用状态</th>
                                        <th>操作</th>
                                    </tr>
                                    <tr th:each="baseStation,index:${baseStations}">
                                        <td th:text="${index.index+1}"></td>
                                        <td th:text="${baseStation.no}"></td>
                                        <td>
                                            <span th:text="${baseStation.type.desc}"></span>
                                        </td>
                                        <td>
                                            <span th:text="${baseStation.stationType==null?'':baseStation.stationType.desc}"></span>
                                        </td>
                                        <td>
                                            <span th:text="${baseStation.version}"></span>
                                        </td>
                                        <td>
                                            <span th:text="${baseStation.deviceAddr}"></span>
                                        </td>
                                        <td>
                                            <span th:text="${baseStation.describe}"></span>
                                        </td>
                                        <td>
                                            <span th:text="${baseStation.locator.locatorInfo.floorNode?'是':'否'}"></span>
                                        </td>
                                        <td>
                                            <span th:style="${baseStation.getOnlineStyle()}"
                                                  th:text="${baseStation.onlineStatus?'在线':'离线'}"></span>
                                        </td>
                                        <td>
                                            <span th:style="${baseStation.getStatusStyle()}"
                                                  th:text="${baseStation.status?'报警':'未报警'}"></span>
                                        </td>
                                        <td>
                                            <span th:style="${baseStation.getVoltageStatusStyle()}"
                                                  th:text="${baseStation.voltageStatus.desc}"></span>
                                        </td>
                                        <td>
                                            <span th:style="${baseStation.getDismantleStatusStyle()}"
                                                  th:text="${baseStation.dismantleStatus?'正常':'异常'}"></span>
                                        </td>
                                        <td>
                                            <span th:style="${baseStation.getEnableStyle()}"
                                                  th:text="${baseStation.enable?'启用':'禁用'}"></span>
                                        </td>

                                        <td>
                                            <div class="input-group">
                                                <button th:onclick="jsHelper.setCard([[${baseStation.baseStationId}]],[[${baseStation.no}]],[[${baseStation.type.code}]]
                                            ,[[${baseStation.version}]],[[${baseStation.ip}]],[[${baseStation.locator.locatorId}]]
                                            ,[[${baseStation.locator.locatorInfo.floorNode}]],[[${baseStation.deviceAddr}]]
                                            ,[[${baseStation.stationType.code}]],[[${baseStation.describe}]])"
                                                        type="button"
                                                        class="btn btn-info btn-xs m-b-none">编辑
                                                </button>
                                                <button onclick="jsHelper.setEnable(1)"
                                                        th:onclick="|jsHelper.setEnable(${baseStation.baseStationId})|"
                                                        type="button"
                                                        class="btn btn-info btn-xs m-b-none "
                                                        th:class="${baseStation.enable?'btn btn-danger btn-xs m-b-none':'btn btn-info btn-xs m-b-none'}"
                                                        th:text="${baseStation.enable?'禁用':'启用'}">
                                                    启用
                                                </button>
                                                <button th:onclick="|setHandler.delete(${baseStation.no})|"
                                                        type="button"
                                                        class="btn btn-default btn-xs m-b-none">删除
                                                </button>
                                                <div class="input-group-btn" style="width: auto;">
                                                    <button data-toggle="dropdown"
                                                            class="btn btn-white btn-xs "
                                                            type="button">操作 <span
                                                            class="caret"></span>
                                                    </button>
                                                    <ul class="dropdown-menu pull-right">
                                                        <li>
                                                            <a th:href="|javascript:setHandler.setLfScope(${baseStation.baseStationId})|"
                                                               href="javascript:setHandler.setLfScope(1)">设置低频参数</a>
                                                        </li>
                                                        <li>
                                                            <a th:href="|javascript:setHandler.rssiModal(${baseStation.baseStationId})|"
                                                               href="javascript:setHandler.rssiModal(1)">设置433MHz的RSSI过滤功能</a>
                                                        </li>
                                                        <li>
                                                            <a th:href="|javascript:setHandler.buzzerModal(${baseStation.baseStationId})|"
                                                               href="javascript:setHandler.buzzerModal(1)">设置蜂鸣器状态</a>
                                                        </li>
                                                        <li>
                                                            <a th:href="|javascript:setHandler.setDeviceAddr(${baseStation.baseStationId})|"
                                                               href="javascript:setHandler.setDeviceAddr(1)">设置设备地址</a>
                                                        </li>
                                                        <li>
                                                            <a th:href="|javascript:setHandler.setFilterTime(${baseStation.baseStationId})|"
                                                               href="javascript:setHandler.setFilterTime(1)">设置设备过滤等待时间</a>
                                                        </li>
                                                    </ul>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                                <p style="float: left; margin: 20px 0;">
                                    共<span th:text="${totalRecords}"></span>条记录，当前第<span th:text="${pageIndex}"></span>/<span
                                        th:text="${totalPages==0?1:totalPages}"></span>，每页20条记录
                                </p>
                                <ul style="float: right;" class="pagination pagination-split">
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="set_card_modal" class="modal-content-tag">
    <div class="form-horizontal" style="width: 600px;">
        <form id="cardModelForm">
            <div class="form-group">
                <label class="col-sm-3 control-label">基站编号：</label>
                <div class="col-sm-9">
                    <input id="modelId" name="modelId" minlength="2" type="hidden" class="form-control"
                           value="0">
                    <input id="locatorModelId" name="locatorModelId" minlength="2" type="hidden" class="form-control"
                           value="0">
                    <input id="modelNo" type="text" class="form-control" name="modelNo">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">基站版本：</label>
                <div class="col-sm-9">
                    <input id="modelVersion" type="text" class="form-control" name="modelVersion">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">阅读器地址：</label>
                <div class="col-sm-9">
                    <input id="deviceAddr" type="text" class="form-control" name="deviceAddr">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">描述：</label>
                <div class="col-sm-9">
                    <input id="desc" type="text" class="form-control" name="modelVersion">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">设备类型：</label>
                <div class="col-sm-9">
                    <select class="form-control" name="modelType" id="modelType">
                        <option th:selected="*{type==0}" value="0">室外定位基站</option>
                        <option th:selected="*{type==1}" value="1">室内融通基站</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">基站类型：</label>
                <div class="col-sm-9">
                    <select class="form-control" name="modelType" id="stationType">
                        <option th:selected="*{stationType==0}" value="0">半球基站</option>
                        <option th:selected="*{stationType==1}" value="1">融通单元</option>
                        <option th:selected="*{stationType==2}" value="2">微基站</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">是否节点：</label>
                <div class="col-sm-9">
                    <select class="form-control" name="modelFloorNode" id="modelFloorNode">
                        <option th:selected="*{floorNode==0}" value="0">否</option>
                        <option th:selected="*{floorNode==1}" value="1">是</option>
                    </select>
                </div>
            </div>
            <!--            <div class="form-group">-->
            <!--                <label class="col-sm-3 control-label">特定住户立即警报：</label>-->
            <!--                <div class="col-sm-9">-->
            <!--                    <select class="form-control" name="modal_alarmedImmediately" id="modal_alarmedImmediately">-->
            <!--                        <option value="0">否</option>-->
            <!--                        <option value="1">是</option>-->
            <!--                    </select>-->
            <!--                </div>-->
            <!--            </div>-->
            <!--            <div class="form-group">-->
            <!--                <label class="col-sm-3 control-label">警报模板：</label>-->
            <!--                <div class="col-sm-9">-->
            <!--                    <input id="modal_alarmTemplate" type="text" class="form-control" name="modal_alarmTemplate">-->
            <!--                </div>-->
            <!--            </div>-->
        </form>
    </div>
</div>

<div id="set_rssi_modal" class="modal-content-tag">
    <input type="hidden" id="rssi_station_id"/>
    <form class="form-horizontal">
        <div class="form-group">
            <label class="col-sm-7 control-label">启用RSSI过滤功能：</label>
            <div class="col-sm-5">
                <select id="rssi_enabled" class="form-control m-b" name="account">
                    <option value="0">禁用</option>
                    <option value="1">启用</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-7 control-label">RSSI阈值：</label>
            <div class="col-sm-5">
                <input id="rssi_limit" type="text" class="form-control">
            </div>
        </div>
    </form>
</div>

<div id="set_buzzerStatus_modal" class="modal-content-tag">
    <input type="hidden" id="buzzer_station_id"/>
    <form class="form-horizontal">
        <div class="form-group">
            <label class="col-sm-7 control-label">蜂鸣器状态：</label>
            <div class="col-sm-5">
                <select id="buzzer_enabled" class="form-control m-b" name="account">
                    <option value="0">停用</option>
                    <option value="1">启用</option>
                </select>
            </div>
        </div>
    </form>
</div>

<div id="uploadExcel_modal" class="modal-content-tag">
    <div class="form-horizontal" style="width: 479px;">
        <div class="form-group form-inline">
            <label class="col-sm-4 control-label">选择excel：</label>
            <div class="col-sm-8">
                <button class="btn btn-success  dim" type="button" onclick="javascript:$('#updateFile').click()"><i
                        class="fa fa-upload">选择文件</i>
                </button>
                <span class="col-sm-8" style="display: none">文件名称</span>
                <input type="file" name="updateFile" id="updateFile" accept="application/vnd.ms-excel" required
                       style="display: none">
            </div>
        </div>
    </div>
</div>

<!--基础框架js-->
<script src="../../resource/js/jquery.min.js" th:src="@{/resource/js/jquery.min.js?20190316}"></script>
<script src="../../resource/js/bootstrap.min.js" th:src="@{/resource/js/bootstrap.min.js?20190316}"></script>

<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20190316"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-utils.js?20190316}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-init.js?20190316?1234567"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-init.js?20190316(123)}"></script>
<script src="../../resource/hotui/js/content.min.js" th:src="@{/resource/hotui/js/content.min.js}"></script>

<script src="../../resource/hotui/js/plugins/datetimepick/js/moment.min.js"
        th:src="@{/resource/hotui/js/plugins/datetimepick/js/moment.min.js}"></script>

<script src="../../resource/hotui/js/plugins/datetimepick/js/daterangepicker.js"
        th:src="@{/resource/hotui/js/plugins/datetimepick/js/daterangepicker.js}"></script>

<script src="../../resource/lib/bootstrap-datepicker/js/bootstrap-datepicker.min.js"
        th:src="@{/resource/lib/bootstrap-datepicker/js/bootstrap-datepicker.min.js}"></script>
<script src="../../resource/lib/bootstrap-datepicker/js/locales/bootstrap-datepicker.zh-CN.min.js"
        th:src="@{/resource/lib/bootstrap-datepicker/js/locales/bootstrap-datepicker.zh-CN.min.js}"></script>

<script src="../../resource/js/switchery.min.js" th:src="@{/resource/js/switchery.min.js}"></script>

<script src="../../resource/js/plugins/validate/jquery.validate.min.js"
        th:src="@{/resource/js/plugins/validate/jquery.validate.min.js}"></script>

<script src="../../resource/js/plugins/validate/messages_zh.min.js"
        th:src="@{/resource/js/plugins/validate/messages_zh.min.js}"></script>
<script src="../../resource/hotui/js/hot/bootstrap.hot.extra-validate.js"
        th:src="@{/resource/hotui/js/hot/bootstrap.hot.extra-validate.js}"></script>

<script src="../../resource/hotui/plugins/zyUpload/core/zyFile.js"
        th:src="@{/resource/hotui/plugins/zyUpload/core/zyFile.js}"></script>
<script src="../../resource/hotui/plugins/zyUpload/control/js/zyUpload.js"
        th:src="@{/resource/hotui/plugins/zyUpload/control/js/zyUpload.js}"></script>
<script src="../../resource/hotui/js/plugins/ajaxfileupload.js"
        th:src="@{/resource/hotui/js/plugins/ajaxfileupload.js}"></script>


<script type="text/javascript" th:inline="javascript">
    const pageIndex = /*[[${pageIndex}]]*/  1;
    const totalPages = /*[[${totalPages}]]*/  0;
    const pageUri = /*[[@{/equipment/base/station/list}]]*/  "";
    const equipmentApiBase = /*[[@{/equipment}]]*/  "/equipment";
    const apiUri = /*[[@{/api/device/base}]]*/  "/equipment";
</script>

<script>
    const cmdCode = {
        setLfScope: "48",
        setRssiFilter: "49",
        setBuzzerStatus: "4B",
        setDeviceAddr: "51",
        setFilterTime: "53"
    };

    var rssiModal = $("#set_rssi_modal").modal("设置433M的RSSI过滤功能", function () {
        setHandler.setRssiFilter();
    });

    var buzzerModal = $("#set_buzzerStatus_modal").modal("设置蜂鸣器状态", function () {
        setHandler.setBuzzerStatus();
    });

    $(function () {
        //初始化分页
        var pageinate = new hot.paging(".pagination", pageIndex, totalPages, 7);

        pageinate.init(function (p) {
            jsHelper.search(p);
        });
        $(document).keyup(function (event) {
            if (event.keyCode == 13) {
                $(".searchBtn").trigger("click");
            }
        });

        $("input[name=chkAll]").change(function () {
            if ($(this).prop("checked")) {
                $("input[name=chkUser]").prop("checked", "checked");
            } else {
                $("input[name=chkUser]").removeAttr("checked");
            }
        });
        jsHelper.init();
    });

    var setCardModel = $("#set_card_modal").modal("基站详情", function () {
        $("#cardModelForm").submit();
    });

    var uploadExcelModal = $("#uploadExcel_modal").modal("基站excel导入", function () {
        jsHelper.uploadExcel();
    });


    var jsHelper = {
        init: function () {
        },
        search: function (pageIndex) {
            $("input[name=pageIndex]").val(pageIndex);
            $("#searchForm").submit();
        },
        searchAll: function () {
            window.location.href = pageUri;
        },
        /**
         * 修改状态
         * @param dataId
         */
        setEnable: function (dataId) {
            hot.ajax("/equipment/edit/base/station/enable", {
                baseStationId: dataId
            }, function (ret) {
                if (ret.resultCode === 2000) {
                    hot.tip.success("操作成功", function () {
                        window.location.reload();
                    })
                } else {
                    hot.tip.error("操作失败-" + ret.resultMsg);
                }
            }, function () {
            }, "post");
        },
        setDir: function (dataId) {
            hot.ajax("/equipment/edit/base/station/dismantle", {
                baseStationId: dataId
            }, function (ret) {
                if (ret.resultCode === 2000) {
                    hot.tip.success("操作成功", function () {
                        window.location.reload();
                    })
                } else {
                    hot.tip.error("操作失败-" + ret.resultMsg);
                }
            }, function () {
            }, "post");
        },
        setCard: function (id, no, type, version, ip, locatorId, floorNode, deviceAddr, stationType, describe, alarmedImmediately, alarmTemplate) {
            setCardModel.show(function () {
                if (id != null) {
                    $("#modelId").val(id);
                    $("#modelNo").val(no);
                    $("#modelType").val(type);
                    $("#modelVersion").val(version);
                    $("#modelIp").val(ip);
                    $("#locatorModelId").val(locatorId);
                    $("#modelFloorNode").val(floorNode ? 1 : 0);
                    $("#deviceAddr").val(deviceAddr);
                    $("#stationType").val(stationType);
                    $("#desc").val(describe);
                    // $("#modal_alarmedImmediately").val(alarmedImmediately);
                    // $("#modal_alarmTemplate").val(alarmTemplate);
                }
                $("#cardModelForm").validateCallback(function () {
                    var requestData = {
                        baseStationId: $("#modelId").val(),
                        no: $("#modelNo").val(),
                        type: $("#modelType").val(),
                        version: $("#modelVersion").val(),
                        ip: $("#modelIp").val(),
                        locatorId: $("#locatorModelId").val(),
                        floorNode: $("#modelFloorNode").val(),
                        deviceAddr: $("#deviceAddr").val(),
                        describe: $("#desc").val(),
                        baseStationType: $("#stationType").val()
                        // alarmedImmediately: $("#modal_alarmedImmediately").val(),
                        // alarmTemplate: $("#modal_alarmTemplate").val()
                    };
                    hot.ajax(equipmentApiBase + "/ajax/save/base/station", requestData, function (apiResult) {
                        if (apiResult.resultCode === 2000) {
                            setCardModel.hide(function () {
                                hot.tip.success("设置成功");
                                window.location.reload();
                            });
                        } else {
                            hot.tip.error("设置失败--" + apiResult.resultMsg);
                        }
                    }, function () {
                    }, "post", 300);
                })
            });
        },
        uploadUpdateExcelModal: function () {
            uploadExcelModal.show(function () {
                $("#updateFile").change(function () {
                    $("#updateFile").prev().css("display", "");
                    var filePath = $("#updateFile").val().split("\\");
                    $("#updateFile").prev().text(filePath[filePath.length - 1]);
                })
            });
        },
        uploadExcel: function () {
            hot.managerFileUpload(equipmentApiBase + "/lead/base/station", "updateFile", null, function (data) {
                if (data == 1) {
                    window.location.reload();
                }
            });
        },
    };

    var setHandler = {
        getStation: function (stationId, callback) {
            hot.ajax(apiUri + "/" + stationId, null, function (apiResult) {
                if (apiResult.resultCode === 2000) {
                    callback(apiResult.data);
                } else {
                    hot.tip.error("操作失败--" + apiResult.resultMsg);
                }
            }, function () {
            }, "post");
        },
        setLfScope: function (stationId) {
            this.getStation(stationId, function (data) {
                layer.prompt({
                    value: data.lfScope,
                    title: "设置低频参数"
                }, function (value, index) {
                    hot.ajax(apiUri + "/set/lfScope", {
                        stationId: stationId,
                        scope: value
                    }, function (apiResult) {
                        if (apiResult.resultCode === 2000) {
                            hot.loading.show();
                            //轮询得到设置结果
                            intervalHelper.init('setHandler.setResult(' + stationId + ',"' + cmdCode.setLfScope + '")');
                        } else {
                            hot.tip.error("请求失败---" + apiResult.resultMsg);
                        }
                    }, function () {
                    }, "post");
                })
            });
        },
        setDeviceAddr: function (stationId) {
            this.getStation(stationId, function (data) {
                layer.prompt({
                    value: data.deviceAddr,
                    title: "设置设备地址"
                }, function (value, index) {
                    hot.ajax(apiUri + "/set/deviceAddr", {
                        stationId: stationId,
                        deviceAddr: value
                    }, function (apiResult) {
                        if (apiResult.resultCode === 2000) {
                            hot.loading.show();
                            //轮询得到设置结果
                            intervalHelper.init('setHandler.setResult(' + stationId + ',"' + cmdCode.setDeviceAddr + '")');
                        } else {
                            hot.tip.error("请求失败---" + apiResult.resultMsg);
                        }
                    }, function () {
                    }, "post");
                })
            })
        },
        setFilterTime: function (stationId) {
            this.getStation(stationId, function (data) {
                layer.prompt({
                    value: data.filterInterval,
                    title: "设置设备过滤等待时间"
                }, function (value, index) {
                    hot.ajax(apiUri + "/set/filterTime", {
                        stationId: stationId,
                        deviceAddr: value
                    }, function (apiResult) {
                        if (apiResult.resultCode === 2000) {
                            hot.loading.show();
                            //轮询得到设置结果
                            intervalHelper.init('setHandler.setResult(' + stationId + ',"' + cmdCode.setFilterTime + '")');
                        } else {
                            hot.tip.error("请求失败---" + apiResult.resultMsg);
                        }
                    }, function () {
                    }, "post");
                })
            })
        },
        rssiModal: function (stationId) {
            this.getStation(stationId, function (data) {
                rssiModal.show(function () {
                    $("#rssi_station_id").val(stationId);

                    if (data.rssiEnabled) {
                        $("#rssi_enabled").val(1);
                        $("#rssi_limit").removeAttr("disabled");
                    } else {
                        $("#rssi_enabled").val(0);
                        $("#rssi_limit").attr("disabled", "disabled");
                    }
                    $("#rssi_enabled").bind('change', function () {
                        let opt = parseInt($(this).val());
                        if (opt === 0) {
                            $("#rssi_limit").attr("disabled", "disabled");
                        } else {
                            $("#rssi_limit").removeAttr("disabled");
                        }
                    });
                })
            });
        },
        setRssiFilter: function () {
            let stationId = $("#rssi_station_id").val();
            let enabled = $("#rssi_enabled").val() === '0';
            let rssiLimit = 0;
            if (enabled) {
                rssiLimit = $.trim($("#rssi_limit").val());
                if (rssiLimit.length === 0) {
                    hot.tip.msg("请输入RSSI阈值");
                    return;
                }
            }
            hot.ajax(apiUri + "/set/rssiFilter", {
                stationId: stationId,
                enabled: enabled,
                limitVal: rssiLimit
            }, function (apiResult) {
                if (apiResult.resultCode === 2000) {
                    hot.loading.show();
                    //轮询得到设置结果
                    intervalHelper.init('jsHelper.setResult(' + stationId + ',"' + cmdCode.setRssiFilter + '")');
                } else {
                    hot.tip.error("请求失败---" + apiResult.resultMsg);
                }
            }, function () {
            }, "post");
        },
        buzzerModal: function (stationId) {
            this.getStation(stationId, function (data) {
                buzzerModal.show(function () {
                    $("#buzzer_station_id").val(stationId);
                    $("#buzzer_enabled").val(data.buzzerStatus ? 1 : 0);
                })
            })
        },
        setBuzzerStatus: function () {
            let stationId = $('#buzzer_station_id').val();
            let enabled = $("#buzzer_enabled").val() === '1';
            hot.ajax(apiUri + "/set/buzzerStatus", {
                stationId: stationId,
                enabled: enabled
            }, function (apiResult) {
                if (apiResult.resultCode === 2000) {
                    hot.loading.show();
                    //轮询得到设置结果
                    intervalHelper.init('jsHelper.setResult(' + stationId + ',"' + cmdCode.setBuzzerStatus + '")');
                } else {
                    hot.tip.error("请求失败---" + apiResult.resultMsg);
                }
            }, function () {
            }, "post");
        },
        setResult: function (stationId, cmdCode) {
            intervalHelper.retryTime--;
            if (intervalHelper.retryTime === 0) {
                //重试次数到了
                intervalHelper.destroy();
                hot.tip.msg("未获得结果响应");
            }
            hot.ajax(apiUri + "/set/result", {
                stationId: stationId,
                cmdCode: cmdCode
            }, function (apiResult) {
                if (apiResult.resultCode !== 2002) {
                    intervalHelper.destroy();
                    if (apiResult.resultCode === 2000) {
                        hot.tip.success("设置成功");
                    } else {
                        hot.tip.error(apiResult.resultMsg);
                    }
                }
            }, function () {
            }, "post");
        },
        delete: function (no) {
            hot.confirm("确定要删除基站" + no + "吗？", function () {
                hot.ajax("/equipment/delete/base/station", {
                    no: no
                }, function (ret) {
                    if (ret.resultCode === 2000) {
                        hot.tip.success("操作成功", function () {
                            window.location.reload();
                        })
                    } else {
                        hot.tip.error("操作失败-" + ret.resultMsg);
                    }
                }, function () {
                }, "post");
            })
        },
    };

    var intervalHelper = {
        instance: null,
        retryTime: 10,
        init: function (func) {
            this.destroy();
            this.instance = setInterval(func, 1000);
        },
        destroy: function () {
            if (this.instance != null) {
                clearInterval(this.instance);
                this.instance = null;
                this.retryTime = 10;
            }
            hot.loading.close();
        }
    }
</script>
</body>
</html>
